package it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyUtils;


import java.util.Vector;

public class FUniqueElementID {
    private Vector randomIDElementVector = new Vector();

    private static FUniqueElementID ourInstance = new FUniqueElementID();

    public static FUniqueElementID getInstance() {
        if (ourInstance == null)
            synchronized (FUniqueElementID.class) {
                if (ourInstance == null)
                    ourInstance = new FUniqueElementID();
            }
        return ourInstance;

    }

    private FUniqueElementID() {

    }

    public int getRandomID(int max) {
        boolean founded = false;

        int index = (int) (Math.random() * max);

        for (int i = 0; i < randomIDElementVector.size(); i++)
            if (((Integer) randomIDElementVector.get(i)).intValue() == index) founded = true;

        if (founded)
            return getRandomID(max);
        else {
            randomIDElementVector.add(new Integer(index));
            return index;
        }
    }


}
